package com.shelpe.services.sinbad.service.simbaproxy;

import java.util.Date;

import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonFormat.Shape;
import com.fasterxml.jackson.annotation.JsonProperty;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

@FeignClient(name = "${feign.simba.name}", url = "${feign.simba.url}")
public interface AdgroupClient {

	@RequestMapping(method = RequestMethod.GET, value = "/simba/taobao.simba.adgroup.add")
	CreateAdgroupResponse createAdgroup(@RequestParam("nick") String nick, @RequestParam("campaign_id") long campaignID,
			@RequestParam("item_id") long productID, @RequestParam("default_price") int defaultPrice,
			@RequestParam("title") String title, @RequestParam("img_url") String imageUrl);

	@Getter
	@Setter
	public static class CreateAdgroupResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_adgroup_add_response")
		private CreateAdgroupRes res;
	}

	@Data
	public static class CreateAdgroupRes {
		private AdgroupDto adgroup;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/simba/taobao.simba.adgroup.update")
	UpdateAdgroupResponse updateAdgroupOnlineStatus(@RequestParam("nick") String nick,
			@RequestParam("adgroup_id") long adgroupID, @RequestParam("online_status") String onlineStatus);

	@Getter
	@Setter
	public static class UpdateAdgroupResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_adgroup_update_response")
		private UpdateAdgroupRes res;
	}

	@Data
	public static class UpdateAdgroupRes {
		private AdgroupOnlineStatusDto adgroup;
	}

	@Data
	public static class AdgroupOnlineStatusDto {
		private String nick;
		@JsonProperty("adgroup_id")
		private long adgroupID;
		@JsonProperty("campaign_id")
		private long campaignID;
		@JsonProperty("category_ids")
		private String categoryIDs;

		@JsonProperty("num_iid")
		private long productID;
		@JsonProperty("product_name")
		private String productName;

		@JsonProperty("is_nonsearch_default_price")
		private boolean nonsearch;
		@JsonProperty("default_price")
		private int defaultPrice;
		@JsonProperty("nonsearch_max_price")
		private int nonsearchMaxPrice;

		@JsonProperty("online_status")
		private String onlineStatus;
		@JsonProperty("offline_type")
		private String offlineType;
		@JsonProperty("creative_title")
		private String creativeName;
		@JsonProperty("creative_img_url")
		private String creativeImgUrl;
		private String reason;

		@JsonProperty("modified_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date modifiedTime;
		@JsonProperty("create_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date createTime;
	}

	@RequestMapping(method = RequestMethod.GET, value = "/simba/taobao.simba.adgroup.delete")
	DeleteAdgroupResponse deleteAdgroup(@RequestParam("nick") String nick, @RequestParam("adgroup_id") long adgroupID);

	@Getter
	@Setter
	public static class DeleteAdgroupResponse extends SimbaProxyBaseDto {
		@JsonProperty("simba_adgroup_delete_response")
		private DeleteAdgroupRes res;
	}

	@Data
	public static class DeleteAdgroupRes {
		private DelAdgroupDto adgroup;
	}

	@Data
	public static class DelAdgroupDto {
		private String nick;
		@JsonProperty("adgroup_id")
		private long adgroupID;
		@JsonProperty("campaign_id")
		private long campaignID;
		@JsonProperty("category_ids")
		private String categoryIDs;

		@JsonProperty("num_iid")
		private long productID;
		@JsonProperty("product_name")
		private String productName;

		@JsonProperty("is_nonsearch_default_price")
		private boolean nonsearch;
		@JsonProperty("default_price")
		private int defaultPrice;
		@JsonProperty("nonsearch_max_price")
		private int nonsearchMaxPrice;

		@JsonProperty("online_status")
		private String onlineStatus;
		@JsonProperty("offline_type")
		private String offlineType;
		@JsonProperty("creative_title")
		private String creativeName;
		@JsonProperty("creative_img_url")
		private String creativeImgUrl;
		private String reason;

		@JsonProperty("modified_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date modifiedTime;
		@JsonProperty("create_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
		private Date createTime;
	}

	@Data
	public static class AdgroupDto {
		private String nick;
		@JsonProperty("adgroup_id")
		private long adgroupID;
		@JsonProperty("campaign_id")
		private long campaignID;
		@JsonProperty("category_ids")
		private String categoryIDs;

		@JsonProperty("num_iid")
		private long productID;
		@JsonProperty("product_name")
		private String productName;

		@JsonProperty("is_nonsearch_default_price")
		private boolean nonsearch;
		@JsonProperty("default_price")
		private int defaultPrice;
		@JsonProperty("nonsearch_max_price")
		private int nonsearchMaxPrice;

		@JsonProperty("online_status")
		private String onlineStatus;
		@JsonProperty("offline_type")
		private String offlineType;
		@JsonProperty("creative_title")
		private String creativeName;
		@JsonProperty("creative_img_url")
		private String creativeImgUrl;
		private String reason;

		@JsonProperty("modified_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
		private Date modifiedTime;
		@JsonProperty("create_time")
		@JsonFormat(shape = Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
		private Date createTime;
	}
}